package cn.jekun.shop.common.service;

import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import cn.jekun.component.base.utils.SqlUtis;
import cn.jekun.component.core.bean.gen.RsAdvertisement;
import cn.jekun.component.core.service.gen.RsAdvertisementService;

@Service(AdService.BEAN_NAME)
public class AdService extends ShopBaseService {
	public static final String BEAN_NAME = "cn.jekun.shop.common.AdService";

	@Resource(name = RsAdvertisementService.BEAN_NAME)
	RsAdvertisementService advertisementService;

	@SuppressWarnings({ "rawtypes","unchecked" })
	public JSONObject getAdimages() {
		
		JSONObject jsonObject = new JSONObject();
		
		try {
			//Page page = new Page();
			//List resultList = new ArrayList();
			Map adMap = new HashMap();
			adMap.put(RsAdvertisement.COL_CHANNEL, "1");//1-手机 , 2-云便利商店终端
			SqlUtis.prepareSql(adMap,SqlUtis.getSQL(adMap, RsAdvertisement.COL_CHANNEL ,Types.VARCHAR,SqlUtis.EQ)
					,SqlUtis.orderBy(RsAdvertisement.COL_SORT));
			
			List<RsAdvertisement> RsAdvertisements = this.advertisementService.list(adMap);
			
			jsonObject.put("data",RsAdvertisements);
		} catch (Exception e) {
			e.printStackTrace();
			return executeRerutnFail(jsonObject);
		}
		
		return executeRerutn(jsonObject);

	}
	

}
